{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.7.9 64-bit (system)"
  },
  "metadata": {
   "interpreter": {
    "hash": "852e1ae7af286e361c3fbe3e50983a403e71a78379adad4bb0110f899e9db4fa"
   }
  },
  "interpreter": {
   "hash": "e79309c8f6622ce988b04c24bb6d5b54a89cf65be865511eaf3b861e4b3f791f"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "# 导入库"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "source": [
    "import efinance as ef"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 使用例子"
   ],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 获取交易所期货信息"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "source": [
    "ef.futures.get_futures_base_info()"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "       期货代码      期货名称        行情ID       市场类型\n",
       "0       ZCM     动力煤主力     115.ZCM        郑商所\n",
       "1     ZC201    动力煤201   115.ZC201        郑商所\n",
       "2        jm      焦炭主力      114.jm        大商所\n",
       "3     j2201    焦炭2201   114.j2201        大商所\n",
       "4       jmm      焦煤主力     114.jmm        大商所\n",
       "..      ...       ...         ...        ...\n",
       "846  jm2109    焦煤2109  114.jm2109        大商所\n",
       "847  071108    IH2108    8.071108        中金所\n",
       "848  070131   IH次主力合约    8.070131        中金所\n",
       "849  070120    IH当月连续     8.07012        中金所\n",
       "850  lu2109  低硫燃油2109  142.lu2109  上海能源期货交易所\n",
       "\n",
       "[851 rows x 4 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>期货代码</th>\n",
       "      <th>期货名称</th>\n",
       "      <th>行情ID</th>\n",
       "      <th>市场类型</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ZCM</td>\n",
       "      <td>动力煤主力</td>\n",
       "      <td>115.ZCM</td>\n",
       "      <td>郑商所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ZC201</td>\n",
       "      <td>动力煤201</td>\n",
       "      <td>115.ZC201</td>\n",
       "      <td>郑商所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>jm</td>\n",
       "      <td>焦炭主力</td>\n",
       "      <td>114.jm</td>\n",
       "      <td>大商所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>j2201</td>\n",
       "      <td>焦炭2201</td>\n",
       "      <td>114.j2201</td>\n",
       "      <td>大商所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>jmm</td>\n",
       "      <td>焦煤主力</td>\n",
       "      <td>114.jmm</td>\n",
       "      <td>大商所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>846</th>\n",
       "      <td>jm2109</td>\n",
       "      <td>焦煤2109</td>\n",
       "      <td>114.jm2109</td>\n",
       "      <td>大商所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>847</th>\n",
       "      <td>071108</td>\n",
       "      <td>IH2108</td>\n",
       "      <td>8.071108</td>\n",
       "      <td>中金所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>848</th>\n",
       "      <td>070131</td>\n",
       "      <td>IH次主力合约</td>\n",
       "      <td>8.070131</td>\n",
       "      <td>中金所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>849</th>\n",
       "      <td>070120</td>\n",
       "      <td>IH当月连续</td>\n",
       "      <td>8.07012</td>\n",
       "      <td>中金所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>850</th>\n",
       "      <td>lu2109</td>\n",
       "      <td>低硫燃油2109</td>\n",
       "      <td>142.lu2109</td>\n",
       "      <td>上海能源期货交易所</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>851 rows × 4 columns</p>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 15
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 获取期货实时行情信息"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "source": [
    "ef.futures.get_realtime_quotes()"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "       期货代码      期货名称   涨跌幅     最新价      最高      最低      今开    涨跌额 换手率    量比  \\\n",
       "0       ZCM     动力煤主力  6.28   836.6   843.8   796.8   796.8   49.4   -  2.82   \n",
       "1     ZC201    动力煤201  6.28   836.6   843.8   796.8   796.8   49.4   -  2.82   \n",
       "2        jm      焦炭主力  5.39  2980.0  2982.0  2833.0  2834.0  152.5   -   1.4   \n",
       "3     j2201    焦炭2201  5.39  2980.0  2982.0  2833.0  2834.0  152.5   -   1.4   \n",
       "4       jmm      焦煤主力   5.0  2354.0  2360.0  2221.0  2221.0  112.0   -  1.42   \n",
       "..      ...       ...   ...     ...     ...     ...     ...    ...  ..   ...   \n",
       "846  jm2109    焦煤2109 -2.28  2748.0  2882.5  2688.0  2845.0  -64.0   -  1.85   \n",
       "847  071108    IH2108 -2.52  3060.0  3130.0  3043.0  3111.2  -79.0   -  0.39   \n",
       "848  070131   IH次主力合约 -2.52  3060.0  3130.0  3043.0  3111.2  -79.0   -  0.57   \n",
       "849  070120    IH当月连续 -2.52  3060.0  3130.0  3043.0  3111.2  -79.0   -  0.39   \n",
       "850  lu2109  低硫燃油2109 -3.79  3123.0  3127.0  3121.0  3121.0 -123.0   -     -   \n",
       "\n",
       "    动态市盈率     成交量            成交额    昨日收盘     总市值 流通市值        行情ID       市场类型  \n",
       "0       -   82954   6850341376.0   793.0       -    -     115.ZCM        郑商所  \n",
       "1       -   82954   6850341376.0   793.0       -    -   115.ZC201        郑商所  \n",
       "2       -  166433  48567923456.0  2830.5       -    -      114.jm        大商所  \n",
       "3       -  166433  48567923456.0  2830.5       -    -   114.j2201        大商所  \n",
       "4       -  238671  32924591872.0  2238.0       -    -     114.jmm        大商所  \n",
       "..    ...     ...            ...     ...     ...  ...         ...        ...  \n",
       "846     -   34029   5656982528.0  2866.0       -    -  114.jm2109        大商所  \n",
       "847     -   14384  13315567616.0  3139.2  918000    -    8.071108        中金所  \n",
       "848     -   14384  13315567616.0  3139.2  918000    -    8.070131        中金所  \n",
       "849     -   14384  13315567616.0  3139.2  918000    -     8.07012        中金所  \n",
       "850     -      22       687420.0  3143.0       -    -  142.lu2109  上海能源期货交易所  \n",
       "\n",
       "[851 rows x 18 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>期货代码</th>\n",
       "      <th>期货名称</th>\n",
       "      <th>涨跌幅</th>\n",
       "      <th>最新价</th>\n",
       "      <th>最高</th>\n",
       "      <th>最低</th>\n",
       "      <th>今开</th>\n",
       "      <th>涨跌额</th>\n",
       "      <th>换手率</th>\n",
       "      <th>量比</th>\n",
       "      <th>动态市盈率</th>\n",
       "      <th>成交量</th>\n",
       "      <th>成交额</th>\n",
       "      <th>昨日收盘</th>\n",
       "      <th>总市值</th>\n",
       "      <th>流通市值</th>\n",
       "      <th>行情ID</th>\n",
       "      <th>市场类型</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ZCM</td>\n",
       "      <td>动力煤主力</td>\n",
       "      <td>6.28</td>\n",
       "      <td>836.6</td>\n",
       "      <td>843.8</td>\n",
       "      <td>796.8</td>\n",
       "      <td>796.8</td>\n",
       "      <td>49.4</td>\n",
       "      <td>-</td>\n",
       "      <td>2.82</td>\n",
       "      <td>-</td>\n",
       "      <td>82954</td>\n",
       "      <td>6850341376.0</td>\n",
       "      <td>793.0</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>115.ZCM</td>\n",
       "      <td>郑商所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ZC201</td>\n",
       "      <td>动力煤201</td>\n",
       "      <td>6.28</td>\n",
       "      <td>836.6</td>\n",
       "      <td>843.8</td>\n",
       "      <td>796.8</td>\n",
       "      <td>796.8</td>\n",
       "      <td>49.4</td>\n",
       "      <td>-</td>\n",
       "      <td>2.82</td>\n",
       "      <td>-</td>\n",
       "      <td>82954</td>\n",
       "      <td>6850341376.0</td>\n",
       "      <td>793.0</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>115.ZC201</td>\n",
       "      <td>郑商所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>jm</td>\n",
       "      <td>焦炭主力</td>\n",
       "      <td>5.39</td>\n",
       "      <td>2980.0</td>\n",
       "      <td>2982.0</td>\n",
       "      <td>2833.0</td>\n",
       "      <td>2834.0</td>\n",
       "      <td>152.5</td>\n",
       "      <td>-</td>\n",
       "      <td>1.4</td>\n",
       "      <td>-</td>\n",
       "      <td>166433</td>\n",
       "      <td>48567923456.0</td>\n",
       "      <td>2830.5</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>114.jm</td>\n",
       "      <td>大商所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>j2201</td>\n",
       "      <td>焦炭2201</td>\n",
       "      <td>5.39</td>\n",
       "      <td>2980.0</td>\n",
       "      <td>2982.0</td>\n",
       "      <td>2833.0</td>\n",
       "      <td>2834.0</td>\n",
       "      <td>152.5</td>\n",
       "      <td>-</td>\n",
       "      <td>1.4</td>\n",
       "      <td>-</td>\n",
       "      <td>166433</td>\n",
       "      <td>48567923456.0</td>\n",
       "      <td>2830.5</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>114.j2201</td>\n",
       "      <td>大商所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>jmm</td>\n",
       "      <td>焦煤主力</td>\n",
       "      <td>5.0</td>\n",
       "      <td>2354.0</td>\n",
       "      <td>2360.0</td>\n",
       "      <td>2221.0</td>\n",
       "      <td>2221.0</td>\n",
       "      <td>112.0</td>\n",
       "      <td>-</td>\n",
       "      <td>1.42</td>\n",
       "      <td>-</td>\n",
       "      <td>238671</td>\n",
       "      <td>32924591872.0</td>\n",
       "      <td>2238.0</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>114.jmm</td>\n",
       "      <td>大商所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>846</th>\n",
       "      <td>jm2109</td>\n",
       "      <td>焦煤2109</td>\n",
       "      <td>-2.28</td>\n",
       "      <td>2748.0</td>\n",
       "      <td>2882.5</td>\n",
       "      <td>2688.0</td>\n",
       "      <td>2845.0</td>\n",
       "      <td>-64.0</td>\n",
       "      <td>-</td>\n",
       "      <td>1.85</td>\n",
       "      <td>-</td>\n",
       "      <td>34029</td>\n",
       "      <td>5656982528.0</td>\n",
       "      <td>2866.0</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>114.jm2109</td>\n",
       "      <td>大商所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>847</th>\n",
       "      <td>071108</td>\n",
       "      <td>IH2108</td>\n",
       "      <td>-2.52</td>\n",
       "      <td>3060.0</td>\n",
       "      <td>3130.0</td>\n",
       "      <td>3043.0</td>\n",
       "      <td>3111.2</td>\n",
       "      <td>-79.0</td>\n",
       "      <td>-</td>\n",
       "      <td>0.39</td>\n",
       "      <td>-</td>\n",
       "      <td>14384</td>\n",
       "      <td>13315567616.0</td>\n",
       "      <td>3139.2</td>\n",
       "      <td>918000</td>\n",
       "      <td>-</td>\n",
       "      <td>8.071108</td>\n",
       "      <td>中金所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>848</th>\n",
       "      <td>070131</td>\n",
       "      <td>IH次主力合约</td>\n",
       "      <td>-2.52</td>\n",
       "      <td>3060.0</td>\n",
       "      <td>3130.0</td>\n",
       "      <td>3043.0</td>\n",
       "      <td>3111.2</td>\n",
       "      <td>-79.0</td>\n",
       "      <td>-</td>\n",
       "      <td>0.57</td>\n",
       "      <td>-</td>\n",
       "      <td>14384</td>\n",
       "      <td>13315567616.0</td>\n",
       "      <td>3139.2</td>\n",
       "      <td>918000</td>\n",
       "      <td>-</td>\n",
       "      <td>8.070131</td>\n",
       "      <td>中金所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>849</th>\n",
       "      <td>070120</td>\n",
       "      <td>IH当月连续</td>\n",
       "      <td>-2.52</td>\n",
       "      <td>3060.0</td>\n",
       "      <td>3130.0</td>\n",
       "      <td>3043.0</td>\n",
       "      <td>3111.2</td>\n",
       "      <td>-79.0</td>\n",
       "      <td>-</td>\n",
       "      <td>0.39</td>\n",
       "      <td>-</td>\n",
       "      <td>14384</td>\n",
       "      <td>13315567616.0</td>\n",
       "      <td>3139.2</td>\n",
       "      <td>918000</td>\n",
       "      <td>-</td>\n",
       "      <td>8.07012</td>\n",
       "      <td>中金所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>850</th>\n",
       "      <td>lu2109</td>\n",
       "      <td>低硫燃油2109</td>\n",
       "      <td>-3.79</td>\n",
       "      <td>3123.0</td>\n",
       "      <td>3127.0</td>\n",
       "      <td>3121.0</td>\n",
       "      <td>3121.0</td>\n",
       "      <td>-123.0</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>22</td>\n",
       "      <td>687420.0</td>\n",
       "      <td>3143.0</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>142.lu2109</td>\n",
       "      <td>上海能源期货交易所</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>851 rows × 18 columns</p>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 16
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 获取单个期货 k 线数据"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "source": [
    "quote_id = '115.ZCM'\r\n",
    "ef.futures.get_quote_history(quote_id)"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "       期货名称 期货代码          日期     开盘     收盘     最高     最低    成交量           成交额  \\\n",
       "0     动力煤主力  ZCM  2015-05-18  440.0  437.6  440.2  437.6     64  2.806300e+06   \n",
       "1     动力煤主力  ZCM  2015-05-19  436.0  437.0  437.6  436.0      6  2.621000e+05   \n",
       "2     动力煤主力  ZCM  2015-05-20  436.8  435.8  437.0  434.8      8  3.487500e+05   \n",
       "3     动力煤主力  ZCM  2015-05-21  438.0  443.2  446.8  437.8     37  1.631850e+06   \n",
       "4     动力煤主力  ZCM  2015-05-22  439.2  441.4  443.8  439.2     34  1.502500e+06   \n",
       "...     ...  ...         ...    ...    ...    ...    ...    ...           ...   \n",
       "1524  动力煤主力  ZCM  2021-08-17  755.0  770.8  776.0  750.6  82373  6.288355e+09   \n",
       "1525  动力煤主力  ZCM  2021-08-18  770.8  776.8  785.8  766.0  77392  6.016454e+09   \n",
       "1526  动力煤主力  ZCM  2021-08-19  776.8  777.6  798.0  764.6  97229  7.597474e+09   \n",
       "1527  动力煤主力  ZCM  2021-08-20  778.0  793.0  795.0  775.2  70549  5.553617e+09   \n",
       "1528  动力煤主力  ZCM  2021-08-23  796.8  836.6  843.8  796.8  82954  6.850341e+09   \n",
       "\n",
       "        振幅   涨跌幅   涨跌额  换手率  \n",
       "0     0.00  0.00   0.0  0.0  \n",
       "1     0.36 -0.32  -1.4  0.0  \n",
       "2     0.50 -0.23  -1.0  0.0  \n",
       "3     2.06  1.65   7.2  0.0  \n",
       "4     1.04  0.09   0.4  0.0  \n",
       "...    ...   ...   ...  ...  \n",
       "1524  3.25 -1.26  -9.8  0.0  \n",
       "1525  2.59  1.76  13.4  0.0  \n",
       "1526  4.30  0.03   0.2  0.0  \n",
       "1527  2.53  1.48  11.6  0.0  \n",
       "1528  5.97  6.28  49.4  0.0  \n",
       "\n",
       "[1529 rows x 13 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>期货名称</th>\n",
       "      <th>期货代码</th>\n",
       "      <th>日期</th>\n",
       "      <th>开盘</th>\n",
       "      <th>收盘</th>\n",
       "      <th>最高</th>\n",
       "      <th>最低</th>\n",
       "      <th>成交量</th>\n",
       "      <th>成交额</th>\n",
       "      <th>振幅</th>\n",
       "      <th>涨跌幅</th>\n",
       "      <th>涨跌额</th>\n",
       "      <th>换手率</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>动力煤主力</td>\n",
       "      <td>ZCM</td>\n",
       "      <td>2015-05-18</td>\n",
       "      <td>440.0</td>\n",
       "      <td>437.6</td>\n",
       "      <td>440.2</td>\n",
       "      <td>437.6</td>\n",
       "      <td>64</td>\n",
       "      <td>2.806300e+06</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>动力煤主力</td>\n",
       "      <td>ZCM</td>\n",
       "      <td>2015-05-19</td>\n",
       "      <td>436.0</td>\n",
       "      <td>437.0</td>\n",
       "      <td>437.6</td>\n",
       "      <td>436.0</td>\n",
       "      <td>6</td>\n",
       "      <td>2.621000e+05</td>\n",
       "      <td>0.36</td>\n",
       "      <td>-0.32</td>\n",
       "      <td>-1.4</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>动力煤主力</td>\n",
       "      <td>ZCM</td>\n",
       "      <td>2015-05-20</td>\n",
       "      <td>436.8</td>\n",
       "      <td>435.8</td>\n",
       "      <td>437.0</td>\n",
       "      <td>434.8</td>\n",
       "      <td>8</td>\n",
       "      <td>3.487500e+05</td>\n",
       "      <td>0.50</td>\n",
       "      <td>-0.23</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>动力煤主力</td>\n",
       "      <td>ZCM</td>\n",
       "      <td>2015-05-21</td>\n",
       "      <td>438.0</td>\n",
       "      <td>443.2</td>\n",
       "      <td>446.8</td>\n",
       "      <td>437.8</td>\n",
       "      <td>37</td>\n",
       "      <td>1.631850e+06</td>\n",
       "      <td>2.06</td>\n",
       "      <td>1.65</td>\n",
       "      <td>7.2</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>动力煤主力</td>\n",
       "      <td>ZCM</td>\n",
       "      <td>2015-05-22</td>\n",
       "      <td>439.2</td>\n",
       "      <td>441.4</td>\n",
       "      <td>443.8</td>\n",
       "      <td>439.2</td>\n",
       "      <td>34</td>\n",
       "      <td>1.502500e+06</td>\n",
       "      <td>1.04</td>\n",
       "      <td>0.09</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1524</th>\n",
       "      <td>动力煤主力</td>\n",
       "      <td>ZCM</td>\n",
       "      <td>2021-08-17</td>\n",
       "      <td>755.0</td>\n",
       "      <td>770.8</td>\n",
       "      <td>776.0</td>\n",
       "      <td>750.6</td>\n",
       "      <td>82373</td>\n",
       "      <td>6.288355e+09</td>\n",
       "      <td>3.25</td>\n",
       "      <td>-1.26</td>\n",
       "      <td>-9.8</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1525</th>\n",
       "      <td>动力煤主力</td>\n",
       "      <td>ZCM</td>\n",
       "      <td>2021-08-18</td>\n",
       "      <td>770.8</td>\n",
       "      <td>776.8</td>\n",
       "      <td>785.8</td>\n",
       "      <td>766.0</td>\n",
       "      <td>77392</td>\n",
       "      <td>6.016454e+09</td>\n",
       "      <td>2.59</td>\n",
       "      <td>1.76</td>\n",
       "      <td>13.4</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1526</th>\n",
       "      <td>动力煤主力</td>\n",
       "      <td>ZCM</td>\n",
       "      <td>2021-08-19</td>\n",
       "      <td>776.8</td>\n",
       "      <td>777.6</td>\n",
       "      <td>798.0</td>\n",
       "      <td>764.6</td>\n",
       "      <td>97229</td>\n",
       "      <td>7.597474e+09</td>\n",
       "      <td>4.30</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.2</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1527</th>\n",
       "      <td>动力煤主力</td>\n",
       "      <td>ZCM</td>\n",
       "      <td>2021-08-20</td>\n",
       "      <td>778.0</td>\n",
       "      <td>793.0</td>\n",
       "      <td>795.0</td>\n",
       "      <td>775.2</td>\n",
       "      <td>70549</td>\n",
       "      <td>5.553617e+09</td>\n",
       "      <td>2.53</td>\n",
       "      <td>1.48</td>\n",
       "      <td>11.6</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1528</th>\n",
       "      <td>动力煤主力</td>\n",
       "      <td>ZCM</td>\n",
       "      <td>2021-08-23</td>\n",
       "      <td>796.8</td>\n",
       "      <td>836.6</td>\n",
       "      <td>843.8</td>\n",
       "      <td>796.8</td>\n",
       "      <td>82954</td>\n",
       "      <td>6.850341e+09</td>\n",
       "      <td>5.97</td>\n",
       "      <td>6.28</td>\n",
       "      <td>49.4</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1529 rows × 13 columns</p>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 17
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 单个期货的 5 分钟K线数据"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "source": [
    "quote_id = '115.ZCM'\r\n",
    "freq = 5\r\n",
    "ef.futures.get_quote_history(quote_id,klt=freq)"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "       期货名称 期货代码                日期     开盘     收盘     最高     最低   成交量  \\\n",
       "0     动力煤主力  ZCM  2021-07-22 21:05  910.0  911.2  924.2  910.0  6864   \n",
       "1     动力煤主力  ZCM  2021-07-22 21:10  911.2  910.8  911.6  910.0  2059   \n",
       "2     动力煤主力  ZCM  2021-07-22 21:15  911.0  909.4  911.4  906.6  3250   \n",
       "3     动力煤主力  ZCM  2021-07-22 21:20  909.4  910.2  910.4  908.6   933   \n",
       "4     动力煤主力  ZCM  2021-07-22 21:25  910.2  909.2  910.6  908.8   777   \n",
       "...     ...  ...               ...    ...    ...    ...    ...   ...   \n",
       "1468  动力煤主力  ZCM  2021-08-20 22:40  831.8  837.4  838.4  831.8  3081   \n",
       "1469  动力煤主力  ZCM  2021-08-20 22:45  838.0  835.8  843.8  834.8  6137   \n",
       "1470  动力煤主力  ZCM  2021-08-20 22:50  835.8  835.8  838.2  835.0  1231   \n",
       "1471  动力煤主力  ZCM  2021-08-20 22:55  835.6  831.4  836.0  830.8  3365   \n",
       "1472  动力煤主力  ZCM  2021-08-20 23:00  831.4  836.6  836.6  831.0  2470   \n",
       "\n",
       "              成交额    振幅   涨跌幅  涨跌额  换手率  \n",
       "0     626957759.0  1.55 -0.48 -4.4  0.0  \n",
       "1     187533679.0  0.18 -0.04 -0.4  0.0  \n",
       "2     295442699.0  0.53 -0.15 -1.4  0.0  \n",
       "3      84808820.0  0.20  0.09  0.8  0.0  \n",
       "4      70831320.0  0.20 -0.11 -1.0  0.0  \n",
       "...           ...   ...   ...  ...  ...  \n",
       "1468  256417960.0  0.79  0.72  6.0  0.0  \n",
       "1469  516067639.0  1.07 -0.19 -1.6  0.0  \n",
       "1470  103099880.0  0.38  0.00  0.0  0.0  \n",
       "1471  279289480.0  0.62 -0.53 -4.4  0.0  \n",
       "1472  207191958.0  0.67  0.63  5.2  0.0  \n",
       "\n",
       "[1473 rows x 13 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>期货名称</th>\n",
       "      <th>期货代码</th>\n",
       "      <th>日期</th>\n",
       "      <th>开盘</th>\n",
       "      <th>收盘</th>\n",
       "      <th>最高</th>\n",
       "      <th>最低</th>\n",
       "      <th>成交量</th>\n",
       "      <th>成交额</th>\n",
       "      <th>振幅</th>\n",
       "      <th>涨跌幅</th>\n",
       "      <th>涨跌额</th>\n",
       "      <th>换手率</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>动力煤主力</td>\n",
       "      <td>ZCM</td>\n",
       "      <td>2021-07-22 21:05</td>\n",
       "      <td>910.0</td>\n",
       "      <td>911.2</td>\n",
       "      <td>924.2</td>\n",
       "      <td>910.0</td>\n",
       "      <td>6864</td>\n",
       "      <td>626957759.0</td>\n",
       "      <td>1.55</td>\n",
       "      <td>-0.48</td>\n",
       "      <td>-4.4</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>动力煤主力</td>\n",
       "      <td>ZCM</td>\n",
       "      <td>2021-07-22 21:10</td>\n",
       "      <td>911.2</td>\n",
       "      <td>910.8</td>\n",
       "      <td>911.6</td>\n",
       "      <td>910.0</td>\n",
       "      <td>2059</td>\n",
       "      <td>187533679.0</td>\n",
       "      <td>0.18</td>\n",
       "      <td>-0.04</td>\n",
       "      <td>-0.4</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>动力煤主力</td>\n",
       "      <td>ZCM</td>\n",
       "      <td>2021-07-22 21:15</td>\n",
       "      <td>911.0</td>\n",
       "      <td>909.4</td>\n",
       "      <td>911.4</td>\n",
       "      <td>906.6</td>\n",
       "      <td>3250</td>\n",
       "      <td>295442699.0</td>\n",
       "      <td>0.53</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>-1.4</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>动力煤主力</td>\n",
       "      <td>ZCM</td>\n",
       "      <td>2021-07-22 21:20</td>\n",
       "      <td>909.4</td>\n",
       "      <td>910.2</td>\n",
       "      <td>910.4</td>\n",
       "      <td>908.6</td>\n",
       "      <td>933</td>\n",
       "      <td>84808820.0</td>\n",
       "      <td>0.20</td>\n",
       "      <td>0.09</td>\n",
       "      <td>0.8</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>动力煤主力</td>\n",
       "      <td>ZCM</td>\n",
       "      <td>2021-07-22 21:25</td>\n",
       "      <td>910.2</td>\n",
       "      <td>909.2</td>\n",
       "      <td>910.6</td>\n",
       "      <td>908.8</td>\n",
       "      <td>777</td>\n",
       "      <td>70831320.0</td>\n",
       "      <td>0.20</td>\n",
       "      <td>-0.11</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1468</th>\n",
       "      <td>动力煤主力</td>\n",
       "      <td>ZCM</td>\n",
       "      <td>2021-08-20 22:40</td>\n",
       "      <td>831.8</td>\n",
       "      <td>837.4</td>\n",
       "      <td>838.4</td>\n",
       "      <td>831.8</td>\n",
       "      <td>3081</td>\n",
       "      <td>256417960.0</td>\n",
       "      <td>0.79</td>\n",
       "      <td>0.72</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1469</th>\n",
       "      <td>动力煤主力</td>\n",
       "      <td>ZCM</td>\n",
       "      <td>2021-08-20 22:45</td>\n",
       "      <td>838.0</td>\n",
       "      <td>835.8</td>\n",
       "      <td>843.8</td>\n",
       "      <td>834.8</td>\n",
       "      <td>6137</td>\n",
       "      <td>516067639.0</td>\n",
       "      <td>1.07</td>\n",
       "      <td>-0.19</td>\n",
       "      <td>-1.6</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1470</th>\n",
       "      <td>动力煤主力</td>\n",
       "      <td>ZCM</td>\n",
       "      <td>2021-08-20 22:50</td>\n",
       "      <td>835.8</td>\n",
       "      <td>835.8</td>\n",
       "      <td>838.2</td>\n",
       "      <td>835.0</td>\n",
       "      <td>1231</td>\n",
       "      <td>103099880.0</td>\n",
       "      <td>0.38</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1471</th>\n",
       "      <td>动力煤主力</td>\n",
       "      <td>ZCM</td>\n",
       "      <td>2021-08-20 22:55</td>\n",
       "      <td>835.6</td>\n",
       "      <td>831.4</td>\n",
       "      <td>836.0</td>\n",
       "      <td>830.8</td>\n",
       "      <td>3365</td>\n",
       "      <td>279289480.0</td>\n",
       "      <td>0.62</td>\n",
       "      <td>-0.53</td>\n",
       "      <td>-4.4</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1472</th>\n",
       "      <td>动力煤主力</td>\n",
       "      <td>ZCM</td>\n",
       "      <td>2021-08-20 23:00</td>\n",
       "      <td>831.4</td>\n",
       "      <td>836.6</td>\n",
       "      <td>836.6</td>\n",
       "      <td>831.0</td>\n",
       "      <td>2470</td>\n",
       "      <td>207191958.0</td>\n",
       "      <td>0.67</td>\n",
       "      <td>0.63</td>\n",
       "      <td>5.2</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1473 rows × 13 columns</p>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 18
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 获取多个期货历史 k 线数据"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "source": [
    "# 多个行情ID构成的列表\r\n",
    "quote_ids = ['115.ZCM','115.ZC109']\r\n",
    "# 一次性获取多个期货的日K线行情\r\n",
    "futures_df = ef.futures.get_quote_history(quote_ids)\r\n",
    "# 查看行情ID 为 '115.ZCM' 的期货行情数据\r\n",
    "futures_df['115.ZCM']"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "Processing => 115.ZCM:  50%|█████     | 1/2 [00:00<00:00,  3.23it/s]"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 更多使用例子详见文档 [efinance-docs](https://efinance.readthedocs.io/)\r\n"
   ],
   "metadata": {}
  }
 ]
}